widget: Add a convenience api to activate actions
authorMatthias Clasen <mclasen@redhat.com>
Sun, 28 Apr 2019 18:04:28 +0000 (18:04 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 28 Apr 2019 23:19:05 +0000 (23:19 +0000)
Since actions are used increasingly, we should
have a convenient way to trigger an action in
the context of a widget.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkwidget.c
gtk/gtkwidget.h

index 48a991be96674f16eef1306d68040410b901b20c..a173aea1d1ab9c83f578d88e57f6e533d8a57e07 100644 (file)
@@ -4538,13 +4538,14 @@ gtk_widget_get_realized
 gtk_widget_get_mapped
 gtk_widget_device_is_shadowed
 gtk_widget_get_modifier_mask
-gtk_widget_insert_action_group
 gtk_widget_get_opacity
 gtk_widget_set_opacity
 gtk_widget_get_overflow
 gtk_widget_set_overflow
+gtk_widget_insert_action_group
 gtk_widget_list_action_prefixes
 gtk_widget_get_action_group
+gtk_widget_activate_action
 gtk_widget_measure
 gtk_widget_snapshot_child
 gtk_widget_get_next_sibling
index d95415a515fc78a956cd5fa9a6108fcb5bb218fd..c81d97850cb0ac2ef3cc5a7925cbc12cb7b13ff4 100644 (file)
@@ -12890,6 +12890,36 @@ gtk_widget_get_action_group (GtkWidget   *widget,
   return NULL;
 }
 
+/**
+ * gtk_widget_activate_action:
+ * @widget: a #GtkWidget
+ * @name: a prefixed action name
+ * @parameter: parameters that required by the action
+ *
+ * Looks up the action in the action groups associated
+ * with @widget and its ancestors, and activates it.
+ *
+ * The action name is expected to be prefixed with the
+ * prefix that was used when adding the action group
+ * with gtk_widget_insert_action_group().
+ *
+ * The @parameter must match the actions expected parameter
+ * type, as returned by g_action_get_parameter_type().
+ */
+void
+gtk_widget_activate_action (GtkWidget  *widget,
+                            const char *name,
+                            GVariant   *parameter)
+{
+  GtkActionMuxer *muxer;
+
+  muxer = _gtk_widget_get_action_muxer (widget, FALSE);
+  if (muxer)
+    g_action_group_activate_action (G_ACTION_GROUP (muxer),
+                                    name,
+                                    parameter);
+}
+
 void
 gtk_widget_cancel_event_sequence (GtkWidget             *widget,
                                   GtkGesture            *gesture,
index 9b17b568452087edc9145f19d7728ffb44160924..5fa35ef1ab39bb054c288c89a3a31b189126efc4 100644 (file)
@@ -1011,6 +1011,11 @@ GActionGroup           *gtk_widget_get_action_group     (GtkWidget             *
 GDK_AVAILABLE_IN_ALL
 const gchar **          gtk_widget_list_action_prefixes (GtkWidget             *widget);
 
+GDK_AVAILABLE_IN_ALL
+void                    gtk_widget_activate_action      (GtkWidget  *widget,
+                                                         const char *name,
+                                                         GVariant   *parameter);
+
 GDK_AVAILABLE_IN_ALL
 void                    gtk_widget_set_font_map         (GtkWidget             *widget,
                                                          PangoFontMap          *font_map);